home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / vmsvt.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  351 lines

  1. /*
  2.  *  VMS terminal handling routines
  3.  *
  4.  *  Known types are:
  5.  *    VT52, VT100, and UNKNOWN (which is defined to be an ADM3a)
  6.  *    written by Curtis Smith
  7.  */
  8.  
  9. #include        <stdio.h>
  10. #include        "estruct.h"
  11. #include    "edef.h"
  12.  
  13. #if     VMSVT
  14.  
  15. #define    termdef    1            /* don't define "term" external */
  16.  
  17. #include <ssdef.h>        /* Status code definitions        */
  18. #include <descrip.h>        /* Descriptor structures        */
  19. #include <iodef.h>        /* IO commands                */
  20. #include <ttdef.h>        /* tty commands                */
  21.  
  22. extern  int     ttopen();               /* Forward references.          */
  23. extern  int     ttgetc();
  24. extern  int     ttputc();
  25. extern  int     ttflush();
  26. extern  int     ttclose();
  27. extern  int    vmsopen();
  28. extern    int    vmskopen();
  29. extern    int    vmskclose();
  30. extern  int    vmseeol();
  31. extern  int    vmseeop();
  32. extern  int    vmsbeep();
  33. extern  int    vmsmove();
  34. extern    int    vmsrev();
  35. extern    int    vmscres();
  36. extern  int    eolexist;
  37. #if    COLOR
  38. extern    int    vmsfcol();
  39. extern    int    vmsbcol();
  40. #endif
  41.  
  42. #define    NROWS    24            /* # of screen rolls        */
  43. #define    NCOLS    80            /* # of screen columns        */
  44. #define    MARGIN    8            /* size of minimim margin and    */
  45. #define    SCRSIZ    64            /* scroll size for extended lines */
  46. #define    NPAUSE    100            /* # times thru update to pause */
  47.  
  48. /*
  49.  * Dispatch table. All the
  50.  * hard fields just point into the
  51.  * terminal I/O code.
  52.  */
  53. TERM    term    = {
  54.     NROWS - 1,
  55.     NROWS - 1,
  56.     NCOLS,
  57.     NCOLS,
  58.     MARGIN,
  59.     SCRSIZ,
  60.     NPAUSE,
  61.         &vmsopen,
  62.         &ttclose,
  63.     &vmskopen,
  64.     &vmskclose,
  65.         &ttgetc,
  66.         &ttputc,
  67.         &ttflush,
  68.         &vmsmove,
  69.         &vmseeol,
  70.         &vmseeop,
  71.         &vmsbeep,
  72.         &vmsrev,
  73.         &vmscres
  74. #if    COLOR
  75.     , &vmsfcol,
  76.     &vmsbcol
  77. #endif
  78. };
  79.  
  80. char * termeop;            /* Erase to end of page string        */
  81. int eoppad;            /* Number of pad characters after eop    */
  82. char * termeol;            /* Erase to end of line string        */
  83. int eolpad;            /* Number of pad characters after eol    */
  84. char termtype;            /* Terminal type identifier        */
  85.  
  86.  
  87. /*******
  88.  *  ttputs - Send a string to ttputc
  89.  *******/
  90.  
  91. ttputs(string)
  92. char * string;
  93. {
  94.     while (*string != '\0')
  95.         ttputc(*string++);
  96. }
  97.  
  98.  
  99. /*******
  100.  *  vmspad - Pad the output after an escape sequence
  101.  *******/
  102.  
  103. vmspad(count)
  104. int count;
  105. {
  106.     while (count-- > 0)
  107.         ttputc('\0');
  108. }
  109.  
  110.  
  111. /*******
  112.  *  vmsmove - Move the cursor
  113.  *******/
  114.  
  115. vmsmove(row, col)
  116. {
  117.     switch (termtype) {
  118.         case TT$_UNKNOWN:
  119.             ttputc('\033');
  120.             ttputc('=');
  121.             ttputc(row+' ');
  122.             ttputc(col+' ');
  123.             break;
  124.         case TT$_VT52:
  125.             ttputc('\033');
  126.             ttputc('Y');
  127.             ttputc(row+' ');
  128.             ttputc(col+' ');
  129.             break;
  130.                 case TT$_VT100:         /* I'm assuming that all these  */
  131.                 case TT$_VT101:         /* are a super set of the VT100 */
  132.                 case TT$_VT102:         /* If I'm wrong, just remove    */
  133.                 case TT$_VT105:         /* those entries that aren't.   */
  134.                 case TT$_VT125:
  135.                 case TT$_VT131:
  136.                 case TT$_VT132:
  137.                 case TT$_VT200_SERIES:
  138.             {
  139.                 char buffer[24];
  140.  
  141.                 sprintf(buffer, "\033[%d;%dH", row+1, col+1);
  142.                 ttputs(buffer);
  143.                 vmspad(50);
  144.             }
  145.     }
  146. }
  147.  
  148. /*******
  149.  *  vmsrev - set the reverse video status
  150.  *******/
  151.  
  152. vmsrev(status)
  153.  
  154. int status;    /* TRUE = reverse video, FALSE = normal video */
  155. {
  156.     switch (termtype) {
  157.         case TT$_UNKNOWN:
  158.             break;
  159.         case TT$_VT52:
  160.             break;
  161.         case TT$_VT100:
  162.             if (status) {
  163.                 ttputc('\033');
  164.                 ttputc('[');
  165.                 ttputc('7');
  166.                 ttputc('m');
  167.             } else {
  168.                 ttputc('\033');
  169.                 ttputc('[');
  170.                 ttputc('m');
  171.             }
  172.             break;
  173.     }
  174. }
  175.  
  176. /*******
  177.  *  vmscres - Change screen resolution (which it doesn't)
  178.  *******/
  179.  
  180. vmscres()
  181.  
  182. {
  183.     return(TRUE);
  184. }
  185.  
  186. #if    COLOR
  187. /*******
  188.  *  vmsfcol - Set the forground color (not implimented)
  189.  *******/
  190.  
  191. vmsfcol()
  192. {
  193. }
  194.  
  195. /*******
  196.  *  vmsbcol - Set the background color (not implimented)
  197.  *******/
  198.  
  199. vmsbcol()
  200. {
  201. }
  202. #endif
  203.  
  204. /*******
  205.  *  vmseeol - Erase to end of line
  206.  *******/
  207.  
  208. vmseeol()
  209. {
  210.     ttputs(termeol);
  211.     vmspad(eolpad);
  212. }
  213.  
  214.  
  215. /*******
  216.  *  vmseeop - Erase to end of page (clear screen)
  217.  *******/
  218.  
  219. vmseeop()
  220. {
  221.     ttputs(termeop);
  222.     vmspad(eoppad);
  223. }
  224.  
  225.  
  226. /*******
  227.  *  vmsbeep - Ring the bell
  228.  *******/
  229.  
  230. vmsbeep()
  231. {
  232.     ttputc('\007');
  233. }
  234.  
  235.  
  236. /*******
  237.  *  vmsopen - Get terminal type and open terminal
  238.  *******/
  239.  
  240. vmsopen()
  241. {
  242.     termtype = vmsgtty();
  243.     switch (termtype) {
  244.         case TT$_UNKNOWN:    /* Assume ADM3a    */
  245.             eolexist = FALSE;
  246.             termeop = "\032";
  247.             eoppad = 0;
  248.             break;
  249.         case TT$_VT52:
  250.             termeol = "\033K";
  251.             eolpad = 0;
  252.             termeop = "\033H\033J";
  253.             eoppad = 0;
  254.             break;
  255.         case TT$_VT100:
  256.             revexist = TRUE;
  257.             termeol = "\033[K";
  258.             eolpad = 3;
  259.             termeop = "\033[;H\033[2J";
  260.             eoppad = 50;
  261.             break;
  262.         default:
  263.             puts("Terminal type not supported");
  264.             exit (SS$_NORMAL);
  265.     }
  266.     strcpy(sres, "NORMAL");
  267.         ttopen();
  268. }
  269.  
  270.  
  271. struct iosb {            /* I/O status block            */
  272.     short    i_cond;        /* Condition value            */
  273.     short    i_xfer;        /* Transfer count            */
  274.     long    i_info;        /* Device information            */
  275. };
  276.  
  277. struct termchar {        /* Terminal characteristics        */
  278.     char    t_class;    /* Terminal class            */
  279.     char    t_type;        /* Terminal type            */
  280.     short    t_width;    /* Terminal width in characters        */
  281.     long    t_mandl;    /* Terminal's mode and length        */
  282.     long    t_extend;    /* Extended terminal characteristics    */
  283. };
  284.  
  285. /*******
  286.  *  vmsgtty - Get terminal type from system control block
  287.  *******/
  288.  
  289. vmsgtty()
  290. {
  291.     short fd;
  292.     int status;
  293.     struct iosb iostatus;
  294.     struct termchar tc;
  295.     $DESCRIPTOR(devnam, "SYS$INPUT");
  296.  
  297.     status = sys$assign(&devnam, &fd, 0, 0);
  298.     if (status != SS$_NORMAL)
  299.         exit (status);
  300.  
  301.     status = sys$qiow(        /* Queue and wait        */
  302.         0,            /* Wait on event flag zero    */
  303.         fd,            /* Channel to input terminal    */
  304.         IO$_SENSEMODE,        /* Get current characteristic    */
  305.         &iostatus,        /* Status after operation    */
  306.         0, 0,            /* No AST service        */
  307.         &tc,            /* Terminal characteristics buf    */
  308.         sizeof(tc),        /* Size of the buffer        */
  309.         0, 0, 0, 0);        /* P3-P6 unused            */
  310.  
  311.                     /* De-assign the input device    */
  312.     if (sys$dassgn(fd) != SS$_NORMAL)
  313.         exit(status);
  314.  
  315.     if (status != SS$_NORMAL)    /* Jump out if bad status    */
  316.         exit(status);
  317.     if (iostatus.i_cond != SS$_NORMAL)
  318.         exit(iostatus.i_cond);
  319.  
  320.     return tc.t_type;        /* Return terminal type        */
  321. }
  322.  
  323. vmskopen()
  324.  
  325. {
  326. }
  327.  
  328. vmskclose()
  329.  
  330. {
  331. }
  332.  
  333. #if    FLABEL
  334. fnclabel(f, n)        /* label a function key */
  335.  
  336. int f,n;    /* default flag, numeric argument [unused] */
  337.  
  338. {
  339.     /* on machines with no function keys...don't bother */
  340.     return(TRUE);
  341. }
  342. #endif
  343. #else
  344.  
  345. hellovms()
  346.  
  347. {
  348. }
  349.  
  350. #endif    VMSVT
  351.